package com.example.piece.vm

import androidx.lifecycle.SavedStateHandle
import com.example.base.ext.LoadingView
import com.example.base.vm.BaseViewModel
import com.example.base.vm.OnSuccess
import com.example.piece.entity.*
import com.example.piece.net.NetManager
import com.example.piece.repository.DouYinRepository
import com.example.piece.repository.UerRepository

class UserViewModel(savedStateHandle: SavedStateHandle):BaseViewModel<UerRepository>(savedStateHandle) {
    override fun createRepository(): UerRepository =UerRepository()

    /**
     *             1
     * 用户关注
     *
     * @param status      status 1 关注 0 取消关注
     * @param userId 用户id
     *
     * @see Unit
     */
    fun userAttention(loadingView: LoadingView?, status: String, userId: String,onSuccess: OnSuccess<Unit>) =
        Launch(loadingView) {
            val result = repository.userAttention(status,userId)
            onSuccess(result)
        }

    /**
     *               2
     * 获取指定用户关注列表
     * 需要登录
     *
     * @param page     分页
     * @param targetUserId 用户id
     * @see List<UserAttentionListEntity>
     * @see UserAttentionListEntity
     */
    fun userAttentionList(loadingView: LoadingView?, page: String, targetUserId: String,onSuccess: OnSuccess<List<UserAttentionListEntity>>) =
        Launch(loadingView) {
            val result = repository.userAttentionList(page,targetUserId)
            onSuccess(result)
        }
    /**
     *              3
     * 绑定邀请码
     * 需要登录
     *
     * @param code     邀请码
     *
     * @see Unit
     */
    fun userBindInvite(loadingView: LoadingView?, code: String,onSuccess: OnSuccess<Unit>) =
        Launch(loadingView) {
            val result = repository.userBindInvite(code)
            onSuccess(result)
        }

    /**
     *                 4
     * 检查视频下载权限
     * 视频下载之前调用接口检查权限
     * @see UserCheckPermissionDownloadEntity
     */
    fun userCheckPermissionDownload(loadingView: LoadingView?,onSuccess: OnSuccess<UserCheckPermissionDownloadEntity>) =
        Launch(loadingView) {
            val result = repository.userCheckPermissionDownload()
            onSuccess(result)
        }

    /**
     * 5
     * 注销账户
     * 需要登录
     *
     * @param psw     登录密码
     *
     * @see Unit
     */
    fun userCloseAccount(loadingView: LoadingView?,psw: String,onSuccess: OnSuccess<Unit>) =
        Launch(loadingView) {
            val result = repository.userCloseAccount(psw)
            onSuccess(result)
        }

    /**
     * 6
     * 获取当前登录用户收藏列表
     * 需要登录
     *
     * @param page     分页
     * @see List<AttentionEntity>
     * @see AttentionEntity
     */
    fun userCollectList(loadingView: LoadingView?,page: String,onSuccess: OnSuccess<List<AttentionEntity>>) =
        Launch(loadingView) {
            val result = repository.userCollectList(page)
            onSuccess(result)
        }
    /**
     * 7
     * 获取指定用户的评论列表
     * 需要登录
     *
     * @param page     分页
     * @see List<UserCommentListEntity>
     * @see UserCommentListEntity

     */
    fun userCommentList(loadingView: LoadingView?,page: String,onSuccess: OnSuccess<List<UserCommentListEntity>>) =
        Launch(loadingView) {
            val result = repository.userCommentList(page)
            onSuccess(result)
        }

    /**
     * 8
     * 获取指定用户粉丝列表
     * 需要登录
     *
     * @param page     分页
     * @param targetUserId  用户id
     * @see List<UserAttentionListEntity>
     * @see  UserAttentionListEntity
     */
    fun userFansList(loadingView: LoadingView?,page: String,targetUserId: String,onSuccess: OnSuccess<List<UserAttentionListEntity>>) =
        Launch(loadingView) {
            val result = repository.userFansList(page,targetUserId)
            onSuccess(result)
        }

    /**
     * 9
     * 获取用户信息
     * 需要登录
     *@see UserInfoEntity
     */
    fun userInfo(loadingView: LoadingView?,onSuccess: OnSuccess<UserInfoEntity>) =
        Launch(loadingView) {
            val result = repository.userInfo()
            onSuccess(result)
        }

    /**
     * 10
     * 获取指定用户的信息
     * 需要登录
     *
     * @param targetUserId     目标用户id
     * @see UserInfoTargetEntity

     */
    fun userInfoTarget(loadingView: LoadingView?,targetUserId: String,onSuccess: OnSuccess<UserInfoTargetEntity>) =
        Launch(loadingView) {
            val result = repository.userInfoTarget(targetUserId)
            onSuccess(result)
        }

    /**
     * 11
     * 更新用户信息
     * 需要登录
     *
     * @param content     更新的内容
     * @param type  更新的类目 0 修改头像 先上传到七牛云 1 修改昵称 2 修改签名 3 修改性别 4 修改生日
     * @see Unit
     */
    fun userInfoUpdate(loadingView: LoadingView?,content: String,type: String,onSuccess: OnSuccess<Unit>) =
        Launch(loadingView) {
            val result = repository.userInfoUpdate(content,type)
            onSuccess(result)
        }

    /**
     * 12
     * 获取当前用户帖子列表
     * 需要登录
     *
     * @param page     分页
     *
     * @see List<AttentionEntity>
     * @see AttentionEntity
     */
    fun userJokesList(loadingView: LoadingView?,page: String,onSuccess: OnSuccess<List<AttentionEntity>>) =
        Launch(loadingView) {
            val result = repository.userJokesList(page)
            onSuccess(result)
        }
    /**
     * 13
     * 获取当前用户积分详情
     * 需要登录
     *@see UserLedouInfoEntity
     */
    fun userLedouInfo(loadingView: LoadingView?,onSuccess: OnSuccess<UserLedouInfoEntity>) =
        Launch(loadingView) {
            val result = repository.userLedouInfo()
            onSuccess(result)
        }

    /**
     * 14
     * 获取当前用户积分详情列表
     * 需要登录
     *
     * @param page     分页
     * @see List<UserLedouListEntity>
     * @see UserLedouListEntity
     */
    fun userLedouList(loadingView: LoadingView?,page: String,onSuccess: OnSuccess<List<UserLedouListEntity>>) =
        Launch(loadingView) {
            val result = repository.userLedouList(page)
            onSuccess(result)
        }

    /**
     * 15
     * 当前用户抽奖
     * 需要登录
     *@see Unit
     */
    fun userLedouLottery(loadingView: LoadingView?,onSuccess: OnSuccess<Unit>) =
        Launch(loadingView) {
            val result = repository.userLedouLottery()
            onSuccess(result)
        }
    /**
     * 16
     * 当前用户抽奖列表
     * 需要登录
     *
     * @param page     分页
     * @see List<UserLedouListEntity>
     * @see UserLedouListEntity
     */
    fun userLedouLotteryList(loadingView: LoadingView?,page: String,onSuccess: OnSuccess<List<UserLedouListEntity>>) =
        Launch(loadingView) {
            val result = repository.userLedouLotteryList(page)
            onSuccess(result)
        }
    /**
     * 17
     * 获取当前登录用户点赞列表
     * 需要登录
     *
     * @param page     分页
     *
     * @see List<AttentionEntity>
     * @see AttentionEntity
     */
    fun userLikeList(loadingView: LoadingView?,page: String,onSuccess: OnSuccess<List<AttentionEntity>>) =
        Launch(loadingView) {
            val result = repository.userLikeList(page)
            onSuccess(result)
        }

    /**
     * 18
     * 验证码登录
     *
     * @param code     验证码
     * @param phone     手机号
     * @see UserLoginCodeEntity
     */
    fun userLoginCode(loadingView: LoadingView?,code: String,phone: String,onSuccess: OnSuccess<UserLoginCodeEntity>) =
        Launch(loadingView) {
            val result = repository.userLoginCode(code,phone)
            onSuccess(result)
        }

    /**
     * 19
     * 获取登录验证码
     *不会真实发送验证码，如需发送真实环境下的验证码，请联系管理员开通
     * @param phone     手机号
     * @see Unit
     */
    fun userLoginGetCode(loadingView: LoadingView?,phone: String,onSuccess: OnSuccess<Unit>) =
        Launch(loadingView) {
            val result = repository.userLoginGetCode(phone)
            onSuccess(result)
        }

    /**
     * 20
     * 账号密码登录
     *
     * @param psw     密码 无需加密，后台加密
     * @param phone     手机号
     * @see UserLoginCodeEntity
     */
    fun userLoginPsw(loadingView: LoadingView?,psw: String,phone: String,onSuccess: OnSuccess<UserLoginCodeEntity>) =
        Launch(loadingView) {
            val result = repository.userLoginPsw(psw,phone)
            onSuccess(result)
        }

    /**
     * 21
     * 获取指定用户的消息列表
     *
     * @param page     分页
     * @param type     type=0 赞 type=1 评论 type=2 关注
     * @see List<UserCommentListEntity>
     * @see UserCommentListEntity
     */
    fun userMessageList(loadingView: LoadingView?,page: String,type: String,onSuccess: OnSuccess<List<UserCommentListEntity>>) =
        Launch(loadingView) {
            val result = repository.userMessageList(page,type)
            onSuccess(result)
        }

    /**
     * 22
     * 获取系统消息列表
     *
     * @param page     分页
     * @see List<UserMessageSystemEntity>
     * @see UserMessageSystemEntity
     */
    fun userMessageSystem(loadingView: LoadingView?,page: String,onSuccess: OnSuccess<List<UserMessageSystemEntity>>) =
        Launch(loadingView) {
            val result = repository.userMessageSystem(page)
            onSuccess(result)
        }

    /**
     * 23
     * 获取当前用户的未读消息数
     * 需要登录
     *@see UserMessageUnreadEntity
     */
    fun userMessageUnread(loadingView: LoadingView?,onSuccess: OnSuccess<UserMessageUnreadEntity>) =
        Launch(loadingView) {
            val result = repository.userMessageUnread()
            onSuccess(result)
        }

    /**
     * 24
     * 修改密码
     *需要登录，修改成功之后请让用户重新走登录流程
     * @param old_psw     旧密码
     * @param password     新密码
     * @param new_psw     new_psw
     * @see Unit
     */
    fun userPswChange(loadingView: LoadingView?,old_psw: String, password: String, new_psw: String,onSuccess: OnSuccess<Unit>) =
        Launch(loadingView) {
            val result = repository.userPswChange(old_psw,password,new_psw)
            onSuccess(result)
        }

    /**
     * 25
     * 重置密码
     *密码明文传输，后台加密
     * @param code     验证码
     * @param password     新密码
     * @param phone     手机号
     * @see Unit
     */
    fun userPswReset(loadingView: LoadingView?,code: String, password: String, phone: String,onSuccess: OnSuccess<Unit>) =
        Launch(loadingView) {
            val result = repository.userPswReset(code,password,phone)
            onSuccess(result)
        }
    /**
     * 26
     * 重置密码获取验证码
     *不会真实发送验证码，如需发送真实环境下的验证码，请联系管理员开通
     * @param phone     手机号
     * @see Unit
     */
    fun userPswResetGetCode(loadingView: LoadingView?,phone: String,onSuccess: OnSuccess<Unit>) =
        Launch(loadingView) {
            val result = repository.userPswResetGetCode(phone)
            onSuccess(result)
        }

    /**
     * 27
     * 搜索用户
     * @param keyword     关键字
     * @param page     分页
     * @see List<AttentionUserEntity>
     * @see  AttentionUserEntity
     */
    fun userSearch(loadingView: LoadingView?, keyword: String,page: String,onSuccess: OnSuccess<List<AttentionUserEntity>>) =
        Launch(loadingView) {
            val result = repository.userSearch(keyword,page)
            onSuccess(result)
        }

    /**
     * 28
     * 当前用户签到
     * 需要登录
     *@see UserSigninEntity
     */
    fun userSignin(loadingView: LoadingView?, onSuccess: OnSuccess<UserSigninEntity>) =
        Launch(loadingView) {
            val result = repository.userSignin()
            onSuccess(result)
        }

}